package vip.specimen.system.datasource.validation.implement;

import org.springframework.web.servlet.HandlerMapping;
import vip.specimen.system.datasource.entity.SystemRoleEntity;
import vip.specimen.system.datasource.validation.annotation.RoleCode;
import vip.specimen.system.service.SystemRoleService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashMap;

/**
 * *@Author: 余浪人
 * *@Date：2021/3/22 15:19
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
public class RoleCodeImp implements ConstraintValidator<RoleCode, String> {
    @Resource
    private SystemRoleService roleService;
    @Resource
    private HttpServletRequest request;

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        SystemRoleEntity roleEntity = this.roleService.findSystemRoleEntityByRoleCode(s);
        return (null == roleEntity || roleEntity.getUuid().toString().equals(request.getParameter("uuid")));
    }
}
